#include <algorithm>
#include <stack>

using namespace std;

class MinStack {
   public:
    stack<pair<int, int>> s;

    /** initialize your data structure here. */
    MinStack() {
    }

    void push(int x) {
        if (s.empty()) {
            s.push(pair<int, int>(x, x));
        } else {
            int minVal = s.top().second > x ? x : s.top().second;
            s.push(pair<int, int>(x, minVal));
        }
    }

    void pop() {
        s.pop();
    }

    int top() {
        return s.top().first;
    }

    int min() {
        return s.top().second;
    }
};

/**
 * Your MinStack object will be instantiated and called as such:
 * MinStack* obj = new MinStack();
 * obj->push(x);
 * obj->pop();
 * int param_3 = obj->top();
 * int param_4 = obj->min();
 */